package com.orange.lockscreensettings;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class LockscreenSettingWidgetProvider extends AppWidgetProvider {

	private static final String			ACTION_SETTING	= "com.orange.lockscreen.SETTINGS";
	private static final ComponentName	sCn				= new ComponentName(
																"com.orange.lockscreensettings",
																"com.orange.lockscreensettings.LockscreenSettingWidgetProvider");

	@Override
	public void onDeleted(Context context, int[] appWidgetIds) {
		super.onDeleted(context, appWidgetIds);
	}

	@Override
	public void onDisabled(Context context) {
		super.onDisabled(context);
	}

	@Override
	public void onEnabled(Context context) {
		super.onEnabled(context);
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		super.onReceive(context, intent);
	}

	@Override
	public void onUpdate(Context context, AppWidgetManager appWidgetManager,
			int[] appWidgetIds) {
		RemoteViews views = getRemoteViews(context);
		if (appWidgetIds != null && appWidgetIds.length > 0) {
			appWidgetManager.updateAppWidget(appWidgetIds, views);
		} else {
			appWidgetManager.updateAppWidget(sCn, views);
		}
	}

	private synchronized RemoteViews getRemoteViews(Context context) {
		RemoteViews views = new RemoteViews(context.getPackageName(),
				R.layout.widget_layout);
		Intent intent = new Intent();
		intent.setAction(ACTION_SETTING);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
				| Intent.FLAG_ACTIVITY_CLEAR_TOP);
		PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
		views.setOnClickPendingIntent(R.id.appwidget_layout, pi);
		return views;
	}

}
